Skip to content

Instantly share code, notes, and snippets.

@rbellamy
Last active February 9, 2016 06:57
Show Gist options
  • Select an option

  • Save rbellamy/fac667b424b01585f58c to your computer and use it in GitHub Desktop.

Select an option

Save rbellamy/fac667b424b01585f58c to your computer and use it in GitHub Desktop.
PPAS codegen
SELECT t.typrelid,
format_type(t.oid, NULL) AS alias,
pg_get_userbyid(t.typowner) AS typeowner,
e.typname AS element
FROM pg_type t
JOIN pg_namespace n ON t.typnamespace = n.oid
LEFT OUTER JOIN pg_type e ON e.oid=t.typelem
LEFT OUTER JOIN pg_class ct ON ct.oid=t.typrelid
AND ct.relkind <> 'c'
LEFT OUTER JOIN pg_description des ON (des.objoid=t.oid
AND des.classoid='pg_type'::regclass)
WHERE t.typtype != 'd'
AND t.typname NOT LIKE e'\\_%'
AND n.nspname IN (SELECT * FROM unnest(ARRAY['metrics','terradatum']))
AND ct.oid IS NULL
ORDER BY t.typname;
public class NumberTbl extends JdbcArrayList<java.math.BigDecimal> {
private final ArrayList<BigDecimal> delegate;
public static final String SQL_TYPE_NAME = "terradatum.number_tbl";
/**
* Instance initializor block - necessary because the {@link ArrayList} was null in the constructor during the below
* call to {@code super(array)} - which in turn calls {@code this.add}, thereby throwing a {@link NullPointerException}
*/
{
delegate = new ArrayList<>();
}
/**
* Constructor which accepts an {@link Array}, which is then parsed and hydrated into the delegated {@link java.util.ArrayList}.
*
* The base class uses reflection to determine the various bits needed to fully create this type-safe {@link JdbcArrayList},
* so this constructor can throw numerous exceptions. This is a better solution than a constructor that hides all exceptions
* and prevents the call site from responding accordingly.
* @param array the {@link Array} which is used as the model for this {@link JdbcArrayList}
* @throws SQLException
* @throws NoSuchMethodException
* @throws NoSuchFieldException
* @throws IllegalAccessException
* @throws InvocationTargetException
*/
public NumberTbl(Array array) throws SQLException, NoSuchMethodException, NoSuchFieldException,
IllegalAccessException, InvocationTargetException {
super(array);
}
/**
* Required default constructor.
*/
@SuppressWarnings("unused")
public NumberTbl() {
}
@Override
protected ArrayList<java.math.BigDecimal> delegate() {
return delegate;
}
@Override
public String getSQLTypeName() {
return SQL_TYPE_NAME;
}
}
SELECT attname,
nsp.nspname,
t.typname,
t.typinput
FROM pg_attribute att
JOIN pg_type t ON t.oid=atttypid
JOIN pg_namespace nsp ON t.typnamespace=nsp.oid
LEFT OUTER JOIN pg_type b ON t.typelem=b.oid
LEFT OUTER JOIN pg_collation c ON att.attcollation=c.oid
LEFT OUTER JOIN pg_namespace nspc ON c.collnamespace=nspc.oid
--WHERE att.attrelid=127873
WHERE att.attrelid=128838
ORDER BY attnum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment