Get the default values of table columns in Postgres?

Use the information schema: SELECT column_name, column_default FROM information_schema.columns WHERE (table_schema, table_name) = (‘public’, ‘mytable’) ORDER BY ordinal_position; column_name │ column_default ─────────────┼──────────────────────────────────────── integer │ 2 text │ ‘I am default’::character varying moretext │ ‘I am also default’::character varying unimportant │ (4 rows) Up to the schema naming, this should work in any SQL database system.

Pros and cons of package private classes in Java?

The short answer is – it’s a slightly wider form of private. I’ll assume that you’re familiar with the distinction between public and private, and why it’s generally good practice to make methods and variables private if they’re going to be used solely internally to the class in question. Well, as an extension to that … Read more

PHP Default Function Parameter values, how to ‘pass default value’ for ‘not last’ parameters?

PHP doesn’t support what you’re trying to do. The usual solution to this problem is to pass an array of arguments: function funcName($params = array()) { $defaults = array( // the defaults will be overidden if set in $params ‘value1’ => ‘1’, ‘value2’ => ‘2’, ); $params = array_merge($defaults, $params); echo $params[‘value1’] . ‘, ‘ … Read more

What does “default” mean after a class’ function declaration?

It’s a new C++11 feature. It means that you want to use the compiler-generated version of that function, so you don’t need to specify a body. You can also use = delete to specify that you don’t want the compiler to generate that function automatically. With the introduction of move constructors and move assignment operators, … Read more

Symfony2 Setting a default choice field selection

You can define the default value from the ‘data’ attribute. This is part of the Abstract “field” type (http://symfony.com/doc/2.0/reference/forms/types/field.html) $form = $this->createFormBuilder() ->add(‘status’, ‘choice’, array( ‘choices’ => array( 0 => ‘Published’, 1 => ‘Draft’ ), ‘data’ => 1 )) ->getForm(); In this example, ‘Draft’ would be set as the default selected value.

Default value of a type at Runtime [duplicate]

There’s really only two possibilities: null for reference types and new myType() for value types (which corresponds to 0 for int, float, etc) So you really only need to account for two cases: object GetDefaultValue(Type t) { if (t.IsValueType) return Activator.CreateInstance(t); return null; } (Because value types always have a default constructor, that call to … Read more